<template>
  <div class="sound" >
    <div  v-if="info.sound&&!ifRefresh">
      <SoundPlayer v-if="info.sound" :sound="info.sound" :imgList="img_info"></SoundPlayer>
      <SoundAction :ifAudio="info.sound.videourl===''" ></SoundAction>
      <SoundMeta :info="info" :drama_info="drama_info" :like_info="like_info" :imgList="img_info"></SoundMeta>
    </div>
    <ThumbnailLoading v-else></ThumbnailLoading>
    <slot></slot>
  </div>
</template>

<script>
import ThumbnailLoading from "components/public/ThumbnailLoading"
import SoundPlayer from "components/sound/SoundPlayer"
import SoundAction from "components/sound/SoundAction"
import SoundMeta from "components/sound/SoundMeta"
import { get } from "util/http"
export default {
  props:['scroll'],
  data(){
    return{
      info:{},
      drama_info:{},
      like_info:{},
      danmu_info:'',
      img_info:{},
      id:"",
      ifRefresh:false
    }
  },
  components:{
    SoundPlayer,
    SoundAction,
    SoundMeta,
    ThumbnailLoading
  },
  methods:{
     async getData(){
      this.id=this.$route.params.soundid
      let result=await get({
        url:"/ajax/sound/getsound",
        params:{
          soundid:this.id
        }
      })
      if(result.success){
        this.info=result.info
      }else{
        let redirect=result.info.redirect
        result=await get({
          url:"/ajax/sound/getsound",
          params:{
            soundid:redirect
          }
        })
        this.info=result.info
      }
      let drama_result=await get({
        url:"/ajax/dramaapi/getdramabysound",
        params:{
          sound_id:this.id
        }
      })
      this.drama_info=drama_result.info
      let like_result=await get({
        url:"/ajax/sound/getsoundlike",
        params:{
          sound_id:this.id,
          type:15
        }
      })
      this.like_info=like_result.info
      let danmu_result=await get({
        url:'/ajax/sound/getdm',
        params:{
          soundid:this.id
        }
      })
      this.danmu_info=danmu_result
      // console.log(this.danmu_info)
      let img_result=await get({
        url:"/ajax/sound/getSortedImage",
        params:{
          soundid:this.id
        }
      })
      this.img_info=img_result.info
      await this.$nextTick()
      this.scroll.refresh()
    }
  },
  async mounted(){
    await this.getData()
  },
  watch:{
    // async $route(){
    //   //await this.getData()
    //   //this.ifRefresh=true
    //   //this.$router.go(0)
    //   // this.scroll.scrollTo(0,0)
    //   // await this.$nextTick(()=>{
    //   //   this.ifRefresh=false
    //   // })
    //   this.$router.go(0)
    // }
  }
}
</script>

<style lang="stylus" scoped>
.sound
  width 100%
  height 100%
  flex 1
  display flex
  flex-direction column
  justify-content center
  overflow hidden
</style>